﻿using System.Text.Json.Serialization;

namespace Share.APIs;
public class QAccBal : IcbcApiRequest
{
    internal override string Url => "api/mybank/enterprise/account/qaccbal/V1";

    [JsonPropertyName("trans_code")] public string TransCode => "QACCBAL";
    [JsonPropertyName("cis")] public string Cis { get; set; } = string.Empty;
    [JsonPropertyName("bank_code")] public string BankCode { get; set; } = "102";
    [JsonPropertyName("login_id")] public string LoginId { get; set; } = string.Empty;
    [JsonPropertyName("tran_date")] public string TranDate { get; set; } = DateTime.Today.ToString("yyyyMMdd");
    [JsonPropertyName("f_seq_no")] public string FSeqNo { get; set; } = $"zs{DateTime.Today:yyyyMMdd}{DateTime.Now:HHmmssfff}{Random.Shared.Next()}";
    [JsonPropertyName("language")] public string? Language { get; set; } = "zh_CN";
    [JsonPropertyName("tran_time")] public string TranTime { get; set; } = DateTime.Now.ToString("HHmmssfff");
    [JsonPropertyName("total_num")] public int TotalNum { get => Rd?.Count() ?? 0; }
    [JsonPropertyName("saas_name")] public string? SaasName { get; set; } = string.Empty;

    [JsonPropertyName("rd")] public IEnumerable<QAccbalRequestRd> Rd { get; set; } = [];
}

public class QAccbalRequestRd
{
    [JsonPropertyName("i_seq_no")] public string ISeqNo { get; set; } = string.Empty;
    [JsonPropertyName("account_no")] public string AccountNo { get; set; } = string.Empty;
    [JsonPropertyName("currency")] public string? Currency { get; set; } = "CNY";
    [JsonPropertyName("sub_no")] public string? SubNo { get; set; } = string.Empty;
    [JsonPropertyName("bank_type")] public string BankType { get; set; } = "102";

}

public class QAccBalResponse : IcbcApiResponse
{
    /* 这三个属性在IcbcApiResponse中有定义
    [JsonPropertyName("return_code")] public int ReturnCode { get; set; }
    [JsonPropertyName("return_msg")] public string ReturnMsg { get; set; } = string.Empty;
    [JsonPropertyName("msg_id")] public string MsgId { get; set; } = string.Empty;
    */
    [JsonPropertyName("trans_code")] public string TransCode { get; set; } = string.Empty;
    [JsonPropertyName("cis")] public string Cis { get; set; } = string.Empty;
    [JsonPropertyName("bank_code")] public string BankCode { get; set; } = string.Empty;
    [JsonPropertyName("login_id")] public string LoginId { get; set; } = string.Empty;
    [JsonPropertyName("tran_date")] public string TranDate { get; set; } = string.Empty;
    [JsonPropertyName("tran_time")] public string TranTime { get; set; } = string.Empty;
    [JsonPropertyName("f_seq_no")] public string FSeqNo { get; set; } = string.Empty;
    [JsonPropertyName("rd")] public IEnumerable<QAccBalResponseRd> Rd { get; set; } = [];
}

public class QAccBalResponseRd
{
    [JsonPropertyName("i_seq_no")] public string ISeqNo { get; set; } = string.Empty;
    [JsonPropertyName("account_no")] public string AccountNo { get; set; } = string.Empty;
    [JsonPropertyName("currency")] public string Currency { get; set; } = string.Empty;
    [JsonPropertyName("cash_exf")] public int CashExf { get; set; }
    [JsonPropertyName("account_property")] public int AccountProperty { get; set; }
    [JsonPropertyName("yesterday_balance")] public int YesterdayBalance { get; set; }
    [JsonPropertyName("balance")] public int Balance { get; set; }
    [JsonPropertyName("usable_balance")] public int UsableBalance { get; set; }
    [JsonPropertyName("frozen_amt")] public int FrozenAmt { get; set; }
    [JsonPropertyName("query_time")] public string QueryTime { get; set; } = string.Empty;
    [JsonPropertyName("i_ret_code")] public string IRetCode { get; set; } = string.Empty;
    [JsonPropertyName("i_ret_msg")] public string IRetMsg { get; set; } = string.Empty;
    [JsonPropertyName("bank_type")] public string BankType { get; set; } = string.Empty;
    [JsonPropertyName("account_name")] public string AccountName { get; set; } = string.Empty;
    [JsonPropertyName("hold_amt")] public int HoldAmt { get; set; }
    [JsonPropertyName("last_intr_date")] public string LastIntrDate { get; set; } = string.Empty;
    [JsonPropertyName("sub_no")] public string? SubNo { get; set; } = string.Empty;
    [JsonPropertyName("last_tran_date")] public string LastTranDate { get; set; } = string.Empty;
}
